<?php get_header(); ?>
<?php
     // Get store detail
     global $post;
     $store_id = $post->ID;
     // Update count store view
     $old_store_view = get_post_meta($store_id, 'view_store_metadata', true);     
     update_post_meta($store_id, 'view_store_metadata', (int)$old_store_view + 1);
     
     $prefix_store = get_option('cpx_store_prefix');
     $store_name = $post->post_title.' '.$prefix_store;     
     $store_name_no_kw = $post->post_title;
     $store_des = $post->post_content;
     $store_outlink = cpx_get_outlink($store_id);
     $url_store = get_post_meta($store_id,'url_store_metadata',true);
     $store_logo = get_post_meta($store_id, 'logo_metadata', true);
     if(!$store_logo)
        $store_logo = cpx_get_store_thumb($url_store);
?>

<div class="row-fluid">
    <div class="span8">
        <div class="row-fluid prostores">
            <div class="span3 img-store">
                <a rel="nofollow" href="<?php echo $store_outlink; ?>" target="_blank">    
                    <div class="imgx">
                        <img src="<?php echo $store_logo; ?>" alt="<?php echo $store_name; ?>" title="<?php echo $store_name; ?>" />
                    </div>    
                </a> 
            </div>
            <div class="span9 desstores">
            	<div class="indesstores">
                    <h1><?php echo $store_name;?></h1>
                    <p class="store-description">
                        <?php echo $store_des;?>
                    </p>
                    <p class="shop-store"><a rel="nofollow" href="<?php echo $store_outlink; ?>" target="_blank"><?php echo "Shop at {$store_name_no_kw}"; ;?></a></p>
                </div>
                <?php  
                        if(current_user_can('edit_post',$store_id))
                        {
                            $view = get_post_meta($store_id, 'view_store_metadata', true);
                            $hitcount = cpx_get_cp_hit_count($store_id);
                            $percent_click = ($hitcount/$view)*100;
                            // edit link
                            echo edit_post_link('Edit store','<p>','|',$store_id);
                            // filter all cps of this store
                            $edit_link = admin_url()."edit.php?s&post_status=all&post_type=coupon&action=-1&m=0&ADMIN_FILTER_FIELD_VALUE=$store_id&paged=1&mode=list&action2=-1";
                            echo " | <a href='$edit_link' title='View all coupons of this store'>All coupons</a>";
                            // author
                            $author_id = $post->post_author;
                            echo ' | Author: ';
                            echo the_author_meta('display_name', $author_id);
                            // store view count
                            echo ' | View: '.$view;
                            // aff hit count
                            echo ' | Hit count: '.$hitcount;
                            echo ' ( '.round($percent_click).'% )';
                            echo '</p>';
                        }
                ?>
            </div>
        </div>
        <?php if(is_active_sidebar('cs-content-store-detail-sidebar')) dynamic_sidebar( 'cs-content-store-detail-sidebar' ); ?>
    </div>
    <div class="span4 right-sidebar">
         <?php if(is_active_sidebar('cs-main-sidebar')) dynamic_sidebar( 'cs-main-sidebar' ); ?>
   </div>
</div>
<?php  get_footer(); ?>